package com.baiyue.controller;


import com.baiyue.annotation.SystemLog;
import com.baiyue.entity.TollRules;
import com.baiyue.enums.LogType;
import com.baiyue.model.SelectOptionsResult;
import com.baiyue.model.tollRules.TollRulesDataRequest;
import com.baiyue.model.tollRules.TollRulesDataResponse;
import com.baiyue.result.Result;
import com.baiyue.service.TollRulesService;
import com.baomidou.mybatisplus.plugins.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 *
 * @author 伍波
 * @date 2024-04-30
 */
@RestController
@RequestMapping("/api/tollRules")
@Validated
public class TollRulesController {
    @Autowired
    private TollRulesService tollRulesService;

    /**
     * 新增计费规则
     * @param request
     * @return
     */
    @SystemLog(description = "新增计费规则",type = LogType.NEWADD)
    @PostMapping("/add")
    public Result<Boolean> insert(@RequestBody TollRulesDataRequest request) {
        tollRulesService.insertTollRules(request);
        return Result.success(true);
    }

    @SystemLog(description = "更新计费规则",type = LogType.UPDATE)
    @PostMapping("/update")
    public Result<Boolean> update(@RequestBody TollRulesDataRequest request) {
        return Result.success(tollRulesService.updateTollRules(request));
    }

    @SystemLog(description = "删除计费规则",type = LogType.DELETE)
    @PostMapping("/delete")
    public Result<Boolean> delete(@RequestBody TollRulesDataRequest request) {
        return Result.success(tollRulesService.deleteTollRules(request));
    }

    @PostMapping("/list")
    public Result<Page<TollRulesDataResponse>> findByPage(@RequestBody TollRulesDataRequest request) {
        return Result.success(tollRulesService.findByPage(request));
    }

    @PostMapping("/getById")
    public Result<TollRulesDataResponse> findById(@RequestBody TollRulesDataRequest request) {
        return Result.success(tollRulesService.findById(request));
    }

    @PostMapping("/getSelect")
    public Result<List<SelectOptionsResult>> selectOptions(){
        return Result.success(tollRulesService.selectOptions());
    }
}

